const express = require('express')
const app = express()
const port = 8012

function resData(data) {
	return JSON.stringify({
		code : 200,
		msg : 'success',
		data : data
	})
}

app.all("*", function (req, res, next) {
  //设置允许跨域的域名，*代表允许任意域名跨域
  res.header("Access-Control-Allow-Origin", req.headers.origin || '*');
  // //允许的header类型
  res.header("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With");
  // //跨域允许的请求方式 
  res.header("Access-Control-Allow-Methods", "PUT,POST,GET,DELETE,OPTIONS");
  // 可以带cookies
  res.header("Access-Control-Allow-Credentials", true);
  if (req.method == 'OPTIONS') {
    res.sendStatus(200);
  } else {
    next();
  }
})



app.get('/client/api/user/getAgentNameByDeviceNo', (req, res) => {
	var str = {"code":0,"msg":"success","data":{"agentId":2,"agentName":"尚e充电","type":2}}
    res.send(str)
})

app.get('/client/', (req, res) => {
	var str = {"code":0,"msg":"success","data":{"deviceName":"门卫室西侧","deviceNo":"2007095080","vehicleType":1,"chargeType":2,"priceChargeType":1,"chargeRule":"富贵园小区","remark":"","priceCombo":"[{\"q\":\"8\",\"a\":\"1\"},{\"q\":\"2\",\"a\":\"0.3\"}]","prePayment":0.00,"classRate":"[{\"max\":300,\"min\":0,\"p\":0.00},{\"max\":500,\"min\":300,\"p\":0.00},{\"max\":700,\"min\":500,\"p\":0.00},{\"max\":800,\"min\":700,\"p\":0.00}]","rateMethod":1,"electricityPrice":0.00,"address":"5","agentId":2,"agentType":2,"status":null,"signal":null,"source":null,"phone":"19147218888","collectStatus":2,"connectStatus":2,"subscribe":0,"payWay":null,"internal":0,"portInfos":[{"portNo":1,"status":0,"statusStr":"空闲","doorStatus":0,"batteryType":"","batteryTypeName":null,"soh":0,"soc":0},{"portNo":2,"status":1,"statusStr":"充电中","doorStatus":0,"batteryType":"","batteryTypeName":null,"soh":0,"soc":0},{"portNo":3,"status":0,"statusStr":"空闲","doorStatus":0,"batteryType":"","batteryTypeName":null,"soh":0,"soc":0},{"portNo":4,"status":0,"statusStr":"空闲","doorStatus":0,"batteryType":"","batteryTypeName":null,"soh":0,"soc":0},{"portNo":5,"status":0,"statusStr":"空闲","doorStatus":0,"batteryType":"","batteryTypeName":null,"soh":0,"soc":0},{"portNo":6,"status":0,"statusStr":"空闲","doorStatus":0,"batteryType":"","batteryTypeName":null,"soh":0,"soc":0},{"portNo":7,"status":0,"statusStr":"空闲","doorStatus":0,"batteryType":"","batteryTypeName":null,"soh":0,"soc":0},{"portNo":8,"status":0,"statusStr":"空闲","doorStatus":0,"batteryType":"","batteryTypeName":null,"soh":0,"soc":0},{"portNo":9,"status":0,"statusStr":"空闲","doorStatus":0,"batteryType":"","batteryTypeName":null,"soh":0,"soc":0},{"portNo":10,"status":0,"statusStr":"空闲","doorStatus":0,"batteryType":"","batteryTypeName":null,"soh":0,"soc":0}],"supportAppreciation":0,"userPackage":null,"weChatImg":null,"softVersion":null}}
    res.send(str)
})

app.get('/client/api/user/queryBalance', (req, res) => {
	var str = {"code":0,"msg":"success","data":{"balance":99.97,"bonusBalance":0.00,"totalBalance":99.97}}
    res.send(str)
})


app.listen(port, () => {
  console.log(`Example app listening at http://localhost:${port}`)
})